<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@page import="weaver.hrm.resource.ResourceComInfo" %>
<%@page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.general.BaseBean" %>
<%
    ResourceComInfo resourceComInfo = new ResourceComInfo();
    User user = HrmUserVarify.getUser(request, response);
    int curuserid = user.getUID();
    String requestid = Util.null2String(request.getParameter("requestid"));
    String hideczlx = Util.null2String(request.getParameter("hideczlx"), "1");
    RecordSet rs = new RecordSet();
    BaseBean bb = new BaseBean();
    Map map = new HashMap();

    String sql = "select * from workflow_nodebase";
    rs.executeSql(sql);
    while (rs.next()) {
        String id = Util.null2String(rs.getString("id"));
        String nodename = Util.null2String(rs.getString("nodename"));
        String isstart = Util.null2String(rs.getString("isstart"));
        String isend = Util.null2String(rs.getString("isend"));
        map.put("node_" + id, nodename);
        map.put("node_" + id, nodename);
        map.put("node_" + id, nodename);
        map.put("node_isstart_" + id, isstart);
        map.put("node_isend_" + id, isend);
    }
%>
<%!
    private String removeHtml(String str) {
        String temp = "";
        while (str.indexOf("<") >= 0) {
            int index = str.indexOf("<");
            temp += str.substring(0, index);
            str = str.substring(index + 1);
            index = str.indexOf(">");
            str = str.substring(index + 1);
        }
        temp += str;
        return temp;
    }
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <SCRIPT language="javascript" src="/js/weaver_wev8.js"></script>
    <SCRIPT language="javascript" src="/js/weaverTable_wev8.js"></script>
    <SCRIPT type="text/javascript" src="/formmode/js/WdatePicker/WdatePicker_wev8.js"></script>
    <LINK REL=stylesheet type=text/css HREF=/css/Weaver_wev8.css>
    <link href="/formmode/css/formmode_wev8.css" type="text/css" rel="stylesheet"/>
    <script language=javascript src="/wui/common/jquery/plugin/Listener_wev8.js"></script>
    <SCRIPT type="text/javascript" src="/js/workflow/VCEventHandle_wev8.js"></SCRIPT>
    <script src='echarts.min.js'></script>
    <script src='macarons.js'></script>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
            border: 0;
            list-style-type: none;
            font-size: 14px !important;
            font-family: "Microsoft YaHei" !important;
        }

        td, th {
            border-bottom: 1px solid white;
            border-right: 1px solid white;
            height: 30px;
            text-align: center;
        }

        th {
            font-weight: bold;
        }

        .btn {
            height: 30px;
            width: 1100px;
            border: 1px solid black;
            background-color: white;
        }

        #tablecontainer, #tablecontainer1 {
            width: 100%;
            height: 400px;
            margin: 0 auto;
        }
    </style>
    <script type="text/javascript">
        var isshow = false;

        function showorhidden(id) {
            if (!isshow) {
                $("#jsr" + id).show();
                $("#show" + id).html("隐藏所有接收人");
                isshow = true;
            } else {
                $("#jsr" + id).hide();
                $("#show" + id).html("显示所有接收人");
                isshow = false;
            }
        }

        function reLb() {
            window.parent.WfForm.doRightBtnEvent("BTN_FORWARD");
        }

        function update(nodeid, logid, rzid) {
            showDialog("/jobs/wuxiszf/alllogs_updatelog.jsp?requestid=<%=requestid%>&nodeid=" + nodeid + "&logid=" + logid + "&rzid=" + rzid);
        }

        var dialog = null;

        function showDialog(url, title) {
            var diaHeight = 300;
            var diaWidth = 400;
            dialog = new top.Dialog();
            dialog.currentWindow = window;
            dialog.Drag = true;
            dialog.Width = diaWidth;
            dialog.Height = diaHeight;
            dialog.URL = url;
            dialog.closeBefore = function (res) {
                window.location.reLoad();
            }
            dialog.show();
        }
    </script>
</head>

<body>
<table style="width:100%;" border="0" cellpadding="0" cellspacing="0">
    <tr style="width: 100%;background-color: #4394da;color: white;">
        <th style="width: 4%;border-left: 1px solid white;border-top: 1px solid white;">序号</th>
        <th style="width: 10%;border-top: 1px solid white;">步骤</th>

        <th style="width: 10%;border-top: 1px solid white;">处理人员</th>
        <%if (hideczlx.equals("1")) { %>
        <th style="width: 10%;border-top: 1px solid white;">处理方式</th>
        <%} %>
        <th style="width: 15%;border-top: 1px solid white;">收到时间</th>
        <th style="width: 15%;border-top: 1px solid white;">处理时间</th>
        <th style="width: 30%;border-top: 1px solid white;">处理意见</th>
        <th style="width: 10%;border-top: 1px solid white;">提交人</th>
    </tr>
    <%
        String sql1 = "select distinct ll.nodeid,ll.operator,o.requestid,o.userid,o.workflowid,o.isremark,\n" +
                "o.nodeid nextnodeid,o.receivedate,o.receivetime,o.operatedate,\n" +
                "o.operatetime,n.isstart,h.seclevel,h.dsporder,\n" +
                " dbms_lob.substr(l.remark,  dbms_lob.instr(l.remark,'</',1,1)) remark," +
                "l.destnodeid,l.logtype,l.logid from workflow_currentoperator o left join workflow_requestlog l \n" +
                "on o.requestid=l.requestid and o.nodeid=l.nodeid and o.userid=l.operator \n" +
                "and  (((to_date((l.operatedate||' '||l.operatetime),'yyyy-MM-dd HH24:mi:ss'))+INTERVAL '-5' SECOND \n" +
                "<=to_date((o.operatedate||' '||o.operatetime) ,'yyyy-MM-dd HH24:mi:ss')\n" +
                "and (to_date((l.operatedate||' '||l.operatetime),'yyyy-MM-dd HH24:mi:ss'))+INTERVAL '5' SECOND \n" +
                ">=to_date((o.operatedate||' '||o.operatetime) ,'yyyy-MM-dd HH24:mi:ss'))\n" +
                " or logtype='7') \n" +
                "left join workflow_requestlog ll \n" +
                "on o.requestid=ll.requestid and ','||ll.receivedpersonids||',' like '%,'||o.userid||',%' \n" +
                "and (to_date((ll.operatedate||' '||ll.operatetime),'yyyy-MM-dd HH24:mi:ss'))+INTERVAL '-5' SECOND \n" +
                "<=to_date((o.receivedate||' '||o.receivetime),'yyyy-MM-dd HH24:mi:ss')\n" +
                "and (to_date((ll.operatedate||' '||ll.operatetime),'yyyy-MM-dd HH24:mi:ss'))+INTERVAL '5' SECOND \n" +
                ">=to_date((o.receivedate||' '||o.receivetime),'yyyy-MM-dd HH24:mi:ss')\n" +
                "left join hrmresource h on o.userid=h.id \n" +
                "left join workflow_nodebase n on o.nodeid=n.id \n" +
                "where o.requestid=" + requestid + " order by o.receivedate,o.receivetime,n.isstart desc,h.dsporder asc";

        rs.executeQuery(sql1);
        int index = 0;
        while (rs.next()) {
            String nodeid = Util.null2String(rs.getString("nodeid"));
            String nextnodeid = Util.null2String(rs.getString("nextnodeid"));
            String logtype = Util.null2String(rs.getString("logtype"));
            String operator = Util.null2String(rs.getString("operator"));
            String userid = Util.null2String(rs.getString("userid"));
            String receivedate = Util.null2String(rs.getString("receivedate"));
            String receivetime = Util.null2String(rs.getString("receivetime"));
            String operatedate = Util.null2String(rs.getString("operatedate"));
            String operatetime = Util.null2String(rs.getString("operatetime"));
            String remark = Util.null2String(rs.getString("remark"));
            String isstart = Util.null2String(rs.getString("isstart"));
            bb.writeLog("nodeid::::" + nodeid);
            bb.writeLog("logtype::::" + logtype);
            bb.writeLog("re::::" + requestid);
            bb.writeLog("remark::::" + remark);
            String id = Util.null2String(rs.getString("id"));
            RecordSet rs1 = new RecordSet();
            rs1.executeQuery("select * from workflow_nodecustomrcmenu where nodeid=?", nextnodeid);
            rs1.next();
            String czlx = "";
            if (logtype.equals("0")) {
                czlx = Util.null2String(rs1.getString("submitName7"));
            } else if (logtype.equals("1")) {
                czlx = Util.null2String(rs1.getString("saveName7"));
            } else if (logtype.equals("2")) {
                czlx = Util.null2String(rs1.getString("submitName7"));
            } else if (logtype.equals("3")) {
                czlx = Util.null2String(rs1.getString("rejectName7"));
            } else if (logtype.equals("7")) {
                czlx = Util.null2String(rs1.getString("forwardName7"));
            } else if (logtype.equals("9")) {
                czlx = "批注";
            } else if (logtype.equals("a")) {
                czlx = Util.null2String(rs1.getString("takingOpName7"));
            } else if (logtype.equals("b")) {
                czlx = Util.null2String(rs1.getString("takeBackName7"));
            } else if (logtype.equals("e")) {
                czlx = "强制归档";
            } else if (logtype.equals("h")) {
                czlx = Util.null2String(rs1.getString("forhandName7"));
            } else if (logtype.equals("i")) {
                czlx = "干预";
            } else if (logtype.equals("t")) {
                czlx = "抄送";
            } else if (logtype.equals("")) {
                operatedate = "";
                operatetime = "";
            }
            remark = removeHtml(remark);
            if (remark.equals("")) {
                remark = "<span style='color:gray;'>[未签署]</span>";
            }
            if (isstart.equals("1") && operator.equals("")) {
                operator = userid;
                nodeid = nextnodeid;
            }
            index++;
    %>
    <tr style="<%=index%2==0?"background-color: #f5f5f5;":"" %>">
        <td style="border-left: 1px solid white;"><%=index %>
        </td>
        <td nodeid="<%=nextnodeid %>"><%=Util.null2String(map.get("node_" + nextnodeid)) %>
        </td>

        <td userid="<%=userid %>"><%=resourceComInfo.getLastname(userid) %>
        </td>
        <%if (hideczlx.equals("1")) { %>
        <td><%=czlx %>
        </td>
        <%} %>
        <td><%=receivedate + " " + receivetime %>
        </td>
        <td><%=operatedate + " " + operatetime %>
        </td>
        <td style="text-align: left;"><%=remark %>
        </td>
        <td operator="<%=operator %>"><%=resourceComInfo.getLastname(operator) %>
        </td>
    </tr>
    <%
        }
    %>
</table>
</body>
</html>